<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* 1.可以在一个类上定义一个方法，实例化的对象就会自动拥有这个方法 */
        var arr = [1,2,3];
        Array.prototype.sum = function(arr){
            let total =0;
            for(let i=0;i<arr.length;i++){
                total+=arr[i]
            }
            return total
        
        }
        var res = arr.sum(arr);
        console.log(res);
    </script>
</body>
</html>